// ---> Louie: Unit sample game object
//
//

#include "Unit.h"
#include "MyGL.h"
#include "MathUtility.h"
#include "AssetManager.h"
#include "Error.h"
#include "Game.h"

namespace Engine
{
	Engine::GameObject* CreateUnit()
	{
		return new Unit;
	}

	static bool b = GameObjectFactory_::Instance()->AddType("Unit", &CreateUnit);

	Unit::Unit()
	{
		m_mesh = Engine::TheAssetManager::Instance() ->Get <Engine::Mesh> ("Meshes\\cube.model");
		if(!m_mesh.get())
		{
			Engine::Error("Unable to load model");
		}
	}

	Unit::~Unit()
	{
	}

	void Unit::Update()
	{
		Engine::Agent::Update();
	}

	void Unit::Draw()
	{
		glPushMatrix();

			glEnable(GL_DEPTH_TEST);
			glTranslatef(GetPos().x, GetPos().y, GetPos().z);
			glRotatef(Engine::RadToDeg(GetRot()), 0, 1.0f, 0);
			glScalef(GetScale().x, GetScale().y, GetScale().z);

			glColor3f(1,0,0);
			m_mesh ->Draw();
			glBegin(GL_TRIANGLES);
			glNormal3f(0.0f, 1.0f, 0.0f);
			glVertex3f(0.0f, 0.0f, 2.0f);
			glVertex3f(0.5f, 0.0f, 0.0f);
			glVertex3f(-0.5f, 0.0f, 0.0f);
			glEnd();
			glColor3f(1,1,1);

		glPopMatrix();

		Agent::Draw();
	}
}